package com.lc.afbx.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lc.afbx.R;
import com.lc.afbx.conn.GetApiBusinessDetail;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.util.UtilToast;

import cn.trinea.android.common.util.ToastUtils;

/**
 * Created by Administrator on 2016/6/12.
 */
public class PolicyDetailsCarActivity extends BaseActivity implements View.OnClickListener {


    private TextView policy_detail_car_state_tv;
    private TextView policy_detail_car_num_tv;
    private TextView policy_detail_car_time_tv;
    private TextView policy_detail_car_money_tv;
    private TextView policy_detail_car_shopName_tv;
    private TextView policy_detail_car_company_tv;
    private TextView policy_detail_car_insuranceName_tv;//保险名称
    private TextView policy_detail_car_phone_tv;
    private TextView policy_detail_car_idCard_tv;
    private TextView policy_detail_car_peopleName_tv;//被保险人名称
    private RelativeLayout policy_detail_car_people_info_rl;//被保险人信息  那一行
    private RelativeLayout policy_detail_car_orther_people_info_rl;//被保险人信息的  外层布局
    private ImageView policy_detail_car_arrow_top_iv;
    private ImageView policy_detail_car_arrow_right_iv;

    private boolean flag;

    private GetApiBusinessDetail getApiBusinessDetail = new GetApiBusinessDetail(new AsyCallBack<GetApiBusinessDetail.Info>() {

        @Override
        public void onSuccess(String toast, int type, GetApiBusinessDetail.Info info) throws Exception {

            if (info.data.pstate.equals("2")) {

                policy_detail_car_state_tv.setText("已支付");

            } else {

                policy_detail_car_state_tv.setText("待支付");

            }

            policy_detail_car_num_tv.setText(info.data.ordersn);
            policy_detail_car_time_tv.setText(info.data.posttime);
            policy_detail_car_money_tv.setText("¥" + info.data.total);
            policy_detail_car_shopName_tv.setText(info.data.store);
            policy_detail_car_company_tv.setText(info.data.insurance);
            policy_detail_car_insuranceName_tv.setText(info.data.insurance_name);

            //被保险人信息
            if (info.data.insurant != null) {

                policy_detail_car_phone_tv.setText(info.data.insurant.tel);
                policy_detail_car_idCard_tv.setText(info.data.insurant.id_number);
                policy_detail_car_peopleName_tv.setText(info.data.insurant.name);

            } else {

                policy_detail_car_phone_tv.setText(info.data.tel);
                policy_detail_car_idCard_tv.setText(info.data.id_number);
                policy_detail_car_peopleName_tv.setText(info.data.name);

            }

        }

        @Override
        public void onFail(String toast, int type) throws Exception {

            UtilToast.show(context, toast);

        }
    });


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_policy_detail_car);

        policy_detail_car_state_tv = ((TextView) findViewById(R.id.policy_detail_car_state_tv));
        policy_detail_car_num_tv = ((TextView) findViewById(R.id.policy_detail_car_num_tv));
        policy_detail_car_time_tv = ((TextView) findViewById(R.id.policy_detail_car_time_tv));
        policy_detail_car_money_tv = ((TextView) findViewById(R.id.policy_detail_car_money_tv));
        policy_detail_car_shopName_tv = ((TextView) findViewById(R.id.policy_detail_car_shopName_tv));
        policy_detail_car_company_tv = ((TextView) findViewById(R.id.policy_detail_car_company_tv));
        policy_detail_car_insuranceName_tv = ((TextView) findViewById(R.id.policy_detail_car_insuranceName_tv));

        //被保人信息
        policy_detail_car_phone_tv = ((TextView) findViewById(R.id.policy_detail_car_phone_tv));
        policy_detail_car_idCard_tv = ((TextView) findViewById(R.id.policy_detail_car_idCard_tv));
        policy_detail_car_peopleName_tv = ((TextView) findViewById(R.id.policy_detail_car_peopleName_tv));

        //布局信息
        policy_detail_car_people_info_rl = ((RelativeLayout) findViewById(R.id.policy_detail_car_people_info_rl));
        policy_detail_car_orther_people_info_rl = ((RelativeLayout) findViewById(R.id.policy_detail_car_orther_people_info_rl));
        policy_detail_car_arrow_top_iv = ((ImageView) findViewById(R.id.policy_detail_car_arrow_top_iv));
        policy_detail_car_arrow_right_iv = ((ImageView) findViewById(R.id.policy_detail_car_arrow_right_iv));

        getApiBusinessDetail.id = getIntent().getStringExtra("id");
        getApiBusinessDetail.type = getIntent().getStringExtra("type");
        getApiBusinessDetail.execute(context);

        policy_detail_car_people_info_rl.setOnClickListener(this);

    }

    @Override
    public void onClick(View view) {

        switch (view.getId()) {

            case R.id.back:
                finish();
                return;

            case R.id.policy_detail_car_people_info_rl:

                if (!flag) {

                    flag = true;
                    policy_detail_car_arrow_right_iv.setVisibility(View.VISIBLE);
                    policy_detail_car_arrow_top_iv.setVisibility(View.GONE);
                    policy_detail_car_orther_people_info_rl.setVisibility(View.GONE);

                } else {

                    flag = false;
                    policy_detail_car_arrow_right_iv.setVisibility(View.GONE);
                    policy_detail_car_arrow_top_iv.setVisibility(View.VISIBLE);
                    policy_detail_car_orther_people_info_rl.setVisibility(View.VISIBLE);

                }

                return;


        }


    }


}
